package exercise16;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;

public class FileDome extends BaseManager {
	public void count() throws IOException {
		String path = "D:/JAVA/sun.txt";
		int charNum = 0;
		int wordsNum = 0;
		int lineNum = 0;
		InputStreamReader isr = new InputStreamReader(new FileInputStream(path));
		BufferedReader br = new BufferedReader(isr);
		while (br.read() != -1) {
			String s = br.readLine();
			charNum += s.length();
			wordsNum += s.split(" ").length;
			lineNum++;
		}
		isr.close();// 关闭
		this.logger.info("\n字符数:" + charNum + "\n单词数:" + wordsNum + "\n行 数:" + lineNum);
	}

	public void delete() throws IOException {
		File filesource = new File("D:/JAVA/sun.txt");
		StringBuffer temp = new StringBuffer();
		Scanner input = new Scanner(filesource);
		while (input.hasNext()) {
			String tem = input.nextLine();
			temp.append(tem.replace("John", "") + "\r\n");
		}
		PrintWriter output = new PrintWriter(filesource);
		output.print(temp);
		input.close();
		output.close();
	}

	public void BITFile() {
		FileOutputStream out;
		DataOutputStream dos;
		int sum=0;
		try {
			
			out = new FileOutputStream("ang.dat");
			dos = new DataOutputStream(out);
			for (int i = 1; i <= 100; i++) {
				dos.writeInt(i);
				sum+=i;
			}
			dos.writeInt(sum);
			dos.close();
		} catch (Exception e) {
			this.logger.info(e.toString());
		}
		FileInputStream in;
		DataInputStream dis;
		try {
			in = new FileInputStream("ang.dat");
			dis = new DataInputStream(in);
			while (dis.available() != 0) {
				this.logger.info(dis.readInt());
			}
			dis.close();
		} catch (Exception e) {
			this.logger.info(e.toString());
		}
	}
}
